package com.waitingresult.jdk8;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Author: WangShuai
 * @CreateTime: 2022-10-26  19:57
 * @Description: stream 流
 * @Version: 1.0
 */
public class StreamDemo {
    @Data
    @AllArgsConstructor
    static class Entity{
        private Long id;
        private String name;
    }
    public static void main(String[] args) {
        ArrayList<Entity> list = new ArrayList<>();

        for (long i = 0; i < 20; i++) {
            list.add(new Entity(i, "姓名" + i));
        }
        System.out.println(list.stream()
                .filter(it -> it.getId() % 2 == 0)
                .count());

        Map<Long, Entity> entityMapById = list.stream().collect(Collectors.toMap(Entity::getId, Function.identity()));
        List<String> collect = list.stream().map(Entity::getId).map(String::valueOf).collect(Collectors.toList());

        List<Entity> collect1 = list.stream().peek(it -> {
            it.setId(it.getId() + 1L);
        }).toList();

        System.err.println(collect);
    }
}
